<?php
  
  class ActiveString {
    
    private $_string;
    
    
    function __construct ($string) {
      return $this->_string = $string;
    }
    
    function __tostring() {
      return $this->_string;
    }
    
    function write() {
      echo $this;
      $obj = clone $this;
      return $obj;
    }
    
    # strtoupper
    function upper() {
      $obj = clone $this;
      $obj->_string = strtoupper($obj->_string);
      return $obj;
    }
    
    # strtolower
    function lower() {
      $obj = clone $this;
      $obj->_string = strtolower($obj->_string);
      return $obj;
    }
    
    # str_replace
    function replace($search, $replace) {
      $obj = clone $this;
      $obj->_string = str_replace($search, $replace, $obj->_string);
      return $obj;
    }
    
  }
  
  
  function ActiveString ($string) {
    return new ActiveString ($string);
  }
  
?>